﻿using System;
public class Program
{
    
    public class Clock
    {
        public delegate void ClockAction();
        public event ClockAction Tick;
        public event ClockAction Ring;
        public void ShowTime()
        {
            Console.WriteLine("现在的时间是 " + DateTime.Now.ToString());
        }
        protected virtual void OnTick()
        {   
            if (Tick != null) 
            { 
                Tick();
            }
            else
            {
                Console.WriteLine("Tick event not fire!");
                Console.ReadKey();
            }
        }
        protected virtual void OnRing()
        {
            if (Ring != null)
            { 
                Ring();
            }
            else
            {
                Console.WriteLine("Ring event not fore!");
                Console.ReadKey();
            }
        }
        public void StartTick()
        {
            OnTick();
        }
        public void StartRing()
        {
            OnRing();
        }
    }
    public class subscribEvent
    {
        public void printf1()
        {
            Console.WriteLine("Tick event fire: tic tic tic....");
            Console.WriteLine("Press Enter key to begin to ring");
            Console.ReadKey(); 
        }
        public void printf2()
        {
            Console.WriteLine("Ring event fire: didadidadida");
            Console.ReadKey();
        }
    }
    public static void Main(string[] args)
    {
        subscribEvent v = new subscribEvent();
        Clock clock = new Clock();
        clock.ShowTime();
        clock.Tick += new Clock.ClockAction(v.printf1);
        clock.Ring += new Clock.ClockAction(v.printf2);
        clock.StartTick();
        clock.StartRing();

    }
}
